package com.migule.mymall.mallgetway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class MallCorsConfiguration {
    //跨域设置
    @Bean
    public CorsWebFilter corsWebFilter(){
        //CorsConfigurationSource
        UrlBasedCorsConfigurationSource confSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.addAllowedOrigin("*");//任意来源可以跨域
        corsConfiguration.setAllowCredentials(true);//允许携带cookie/跨域
        confSource.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(confSource);
    }

}
